import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout/index.vue'

import Home from '@/views/Layout/Home'

// 路由懒加载，写成函数的格式
// 看到标识不会加载这个JS文件
// webpackChunkName 用来指明打包后生成的文件名
const Search = () => import(/* webpackChunkName:Search */'@/views/Search/index.vue')
const User = () => import(/* webpackChunkName:User */'@/views/Layout/User')
const SearchResult = () => import(/* webpackChunkName:SearchResult */'@/views/Search/SearchResult.vue')
const ArticleDetail = () => import(/* webpackChunkName:ArticleDetail */'@/views/ArticleDetail')
const UserEdit = () => import(/* webpackChunkName:UserEdit */'@/views/userEdit')
const Chat = () => import(/* webpackChunkName:Chat */'@/views/Chat')
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home', // 默认显示二级页面为home首页
    children: [{
      path: 'home',
      component: Home,
      meta: {
        scrollY: 0
      }
    }, {
      path: 'user', component: User
    }]
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/search/:keywords',
    component: SearchResult
  }, {
    path: '/article_detail',
    component: ArticleDetail
  }, {
    path: '/user/edit',
    component: UserEdit
  }, {
    path: '/Chat',
    component: Chat
  }

]

const router = new VueRouter({
  routes
})

export default router
